package cn.tedu.charging.order.mqtt;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @Author: Miyako
 * @CreateTime: 2024-10-20  17:27
 * @Description: TODO
 */
@Component
public class MqttProducer {


    @Autowired
    MqttClient mqttClient;


    public Boolean publish(String topic , String message){
        Boolean success = false;
        try {
            mqttClient.publish(topic,message.getBytes(),0,true);
            success = true;
        } catch (MqttException e) {
            throw  new RuntimeException(e);
        }
        return success;
    }



}
